package com.gufe.service.admin.impl.club;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.gufe.entity.PPTActiveQueryParam;
import com.gufe.entity.PrecollectMember;
import com.gufe.mapper.admin.allSchool.AllSchoolMapper;
import com.gufe.mapper.admin.club.ActiveMemberMapper;
import com.gufe.result.PageResult;
import com.gufe.service.admin.club.ActiveMemberService;
import com.gufe.vo.PPTvo.ActiveMemberVO;
import com.gufe.vo.PPTvo.CollegeCountVO;
import com.gufe.vo.PPTvo.PersonInfoVO;
import com.gufe.vo.allSchool.PhysicalTestVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class ActiveMemberServiceImpl implements ActiveMemberService {

    @Autowired
    private ActiveMemberMapper activeMemberMapper;

    @Autowired
    private AllSchoolMapper allSchoolMapper;


    /**
     * 分页条件查询预征班现役成员信息
     * @param pptActiveQueryParam
     * @return
     */
    public PageResult<ActiveMemberVO> pageQuery(PPTActiveQueryParam pptActiveQueryParam) {
        // 设置分页参数
        PageHelper.startPage(pptActiveQueryParam.getPage(),pptActiveQueryParam.getPageSize());

        // 执行查询
        List<ActiveMemberVO> activeMemberList = activeMemberMapper.list(pptActiveQueryParam);

        // 解析查询结构并封装
        Page<ActiveMemberVO> p = (Page<ActiveMemberVO>) activeMemberList;

        return new PageResult<>(p.getTotal(), p.getResult());

    }

    /**
     * 统计各个学院现役成员数
     * @return
     */
    public List<CollegeCountVO> getCollegeCount() {
        return activeMemberMapper.getCollegeCount();
    }

    // 根据id获取社团人员个人信息
    public PersonInfoVO getPersonInfo(Integer id) {
        PersonInfoVO personInfo = activeMemberMapper.getPrecollectMemberById(id);
        String studentId = personInfo.getStudentId();
        List<PhysicalTestVO> physicalTestVOList = new ArrayList<>();
        if(studentId != null) {
            physicalTestVOList = allSchoolMapper.getPhysicalTestVOs(studentId);
            personInfo.setPhysicalTestVOList(physicalTestVOList);
        }
        return personInfo;
    }

}
